Barcode scanner sample


Windows Runtime
Devices and sensors, Point of service
Windows RT
en-US
11/25/2013

This sample shows how to create a barcode scanner, claim it for exclusive use, enable it to receive data, and read a barcode. This sample uses Windows.Devices.PointOfService API.

This sample demonstrates these tasks:

  1. Create the barcode scanner

    Uses the BarcodeScanner.GetDefaultAsync to get the first available barcode scanner.

  2. Claim the barcode scanner for exclusive use

    Uses the ClaimScannerAsync to claim the device.

  3. Add event handlers

    Uses DataReceived and ReleaseDeviceRequested events.

    When an application gets a request to release its exclusive claim to the barcode scanner, it must handle the request by retaining the device; otherwise, it will lose its claim. The second scenario in this sample shows the release and retain functionality. The event handler for ReleaseDeviceRequested shows how retain the device.

The app package manifest shows how to specify the device capability name for the Point of Service (POS) devices. All POS apps are required declare DeviceCapability in the app package manifest, either by using "PointofService" as shown in this sample or by using a device specific GUID, such as "C243FFBD-3AFC-45E9-B3D3-2BA18BC7EBC5" for a barcode scanner.

The following list shows the barcode scanners that were used with this sample:

  • Honeywell 1900GSR-2
  • Honeywell 1200g-2
  • Intermec SG20

In addition to the devices listed, you can use barcode scanners from various manufacturers that adhere to the USB HID POS Scanner specification.

To obtain an evaluation copy of Windows 8.1, go to Windows 8.1.

To obtain an evaluation copy of Microsoft Visual Studio 2013, go to Visual Studio 2013.

Note  For Windows 8 app samples, download the Windows 8 app samples pack. The samples in the Windows 8 app samples pack will build and run only on Microsoft Visual Studio 2012.

Related topics

Windows.Devices.PointOfService
USB HID POS Scanner specification
Windows app samples

Operating system requirements

Client
Windows 8.1
Server
Windows Server 2012 R2

Build the sample

  1. Start Visual Studio 2013 and select File > Open > Project/Solution.
  2. Go to the directory in which you unzipped the sample. Go to the directory named for the sample, and double-click the Visual Studio 2013 Solution (.sln) file.
  3. Press F7 or use Build > Build Solution to build the sample.

Run the sample

To debug the app and then run it, press F5 or use Debug > Start Debugging. To run the app without debugging, press Ctrl+F5 or use Debug > Start Without Debugging.